﻿var virualpath = "../../"
$(function () {
    GetMenu()
    GetRescourceAllList()
})

function GetMenu() {
    $.ajax({
        url: virualpath + '/Menu/GetMenuResourceList',
        type: 'get',
        async: true,
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            var resultData = data;
            var str = "";
            if (resultData != undefined) {

                for (var i = 0; i < Object.keys(resultData).length; i++) {
                    var textbooks = resultData[i].Pro_Textbooks.toString();
                    var books = resultData[i].Pro_Books;
                    var websites = resultData[i].Pro_Websites;
                    var obj = {};
                    obj.textbooks = textbooks;
                    obj.books = books;
                    obj.websites = websites;
                    str += "<li><a href='#' onclick='GetRescource(" + JSON.stringify(obj) + ")'><p><span>" + resultData[i].Name + "</span><span id='count'><b></b></span></p></a></li>";
                }
                $("#menu-left").append('<li class="title"><a onclick="GetRescourceAllList()"><p><span style="font-size:16px;color:#555;">全部课程</span><span><b></b></span></p></a></li>');
                $("#menu-left").append(str); 
            }

        }
    })
}
function GetRescourceAllList() {
    $("#Textbook").empty();
    $("#Book").empty();
    $("#Website").empty();
    $.ajax({
        url: virualpath + '/Textbook/GetTextbookAllList',
        type: 'get',
        async: false,
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            var resultData = data;
            var str = "";
            if (resultData != undefined) {
                for (var i = 0; i < Object.keys(resultData).length; i++) {
                    str += '<div class="onelist" id="a' + resultData[i].Id + '"><div class="pic"><img src="'+resultData[i].Filepath + resultData[i].Img + '" width="200" height="275" alt="" /></div ><div class="tit"><span class="font14 bold fray">' + resultData[i].TextName + '</span><br>' + resultData[i].TextAuthor + '<br>' + resultData[i].Publishing + '</div></div>';
                }
                $("#Textbook").append(str);
            }
        }
    })

    $.ajax({
        url: virualpath + '/Book/GetBookAllList',
        type: 'get',
        async: false,
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            var resultData = data;
            var str = "";
            if (resultData != undefined) {
                for (var i = 0; i < Object.keys(resultData).length; i++) {
                    str += '<div class="onelist" id="b' + resultData[i].Id + '"><div class="pic" > <img src="' + resultData[i].Filepath + resultData[i].Img + '" width="244" height="335" alt="" /></div><div class="tit"><span class="font14 bold fray" >' + resultData[i].BookName + '</span><br>' + resultData[i].BookAuthor + '<br>' + resultData[i].Publishing + '</div></div>';
                }
                $("#Book").append(str);
            }
        }
    })

    $.ajax({
        url: virualpath + '/Website/GetWebsiteAllList',
        type: 'get',
        async: false,
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            var resultData = data;
            var str = "";
            if (resultData != undefined) {
                for (var i = 0; i < Object.keys(resultData).length; i++) {
                    str += '<div class="onelist" id="c' + resultData[i].Id + '"><div class="pic"><img src="' + resultData[i].Filepath + resultData[i].Img + '" width="244" height="335" alt="" /></div ><div class="tit"><a href="' + resultData[i].WebUrl + '" target="_blank">' + resultData[i].WebUrl + '</a></div></div>';
                }
                $("#Website").append(str);
            }
        }
    })

} 



function GetRescource(obj) {
    $("#Textbook").empty();
    $("#Book").empty();
    $("#Website").empty();
    $.ajax({
        url: virualpath + '/Textbook/GetByIdTextbookInfo',
        type: 'get',
        data: { "id": "" + obj.textbooks + "" },
        async: false,
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            var resultData = data;
            var str = "";
            if (resultData != undefined) {
                for (var i = 0; i < Object.keys(resultData).length; i++) {
                    str += '<div class="onelist" id="a' + resultData[i].Id + '"><div class="pic"><img src="' + resultData[i].Filepath + resultData[i].Img + '" width="200" height="275" alt="" /></div ><div class="tit"><span class="font14 bold fray">' + resultData[i].TextName + '</span><br>' + resultData[i].TextAuthor + '<br>' + resultData[i].Publishing + '</div></div>';
                }
                $("#Textbook").append(str);
            }
        }
    })

    $.ajax({
        url: virualpath + '/Book/GetByIdBookInfo',
        type: 'get',
        async: false,
        data: { "id": "" + obj.books + "" },
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            var resultData = data;
            var str = "";
            if (resultData != undefined) {
                for (var i = 0; i < Object.keys(resultData).length; i++) {
                    str += '<div class="onelist" id="b' + resultData[i].Id + '"><div class="pic" > <img src="' + resultData[i].Filepath + resultData[i].Img + '" width="244" height="335" alt="" /></div><div class="tit"><span class="font14 bold fray" >' + resultData[i].BookName + '</span><br>' + resultData[i].BookAuthor + '<br>' + resultData[i].Publishing + '</div></div>';
                }
                $("#Book").append(str);
            }
        }
    })

    $.ajax({
        url: virualpath + '/Website/GetByIdWebsiteInfo',
        type: 'get',
        async: false,
        data: { "id": "" + obj.websites + "" },
        dataType: 'json',
        contentType: 'application/json',
        success: function (data) {
            var resultData = data;
            var str = "";
            if (resultData != undefined) {
                for (var i = 0; i < Object.keys(resultData).length; i++) {
                    str += '<div class="onelist" id="c' + resultData[i].Id + '"><div class="pic"><img src="' + resultData[i].Filepath + resultData[i].Img + '" width="244" height="335" alt="" /></div ><div class="tit"><a href="' + resultData[i].WebUrl + '" target="_blank">' + resultData[i].WebUrl + '</a></div></div>';
                }
                $("#Website").append(str);
            }
        }
    })
}